//添加产品图片上传
function imgUpload() {
	var uploadImgMinNum = 1;
	var uploadImgMaxNum = 5;
	var showImg = document.querySelector(".uploadImg label"); 
	var getImg = document.querySelector(".uploadImg input[type='file']"); 
	if(typeof FileReader==='undefined'){ 
	    showImg.innerHTML = "抱歉，你的浏览器不支持 FileReader"; 
	    getImg.setAttribute('disabled','disabled'); 
	}else{ 
	    getImg.addEventListener('change',readFile,false);  
	} 
	function readFile(){ 
		//for(var i=0;i<this.files.length;i++){  
		    var _self = this;
		    var file = this.files[0];
		    if(!/image\/\w+/.test(file.type)){ 
		        alert("请上传图片！"); 
		        return false; 
		    }
		    var reader = new FileReader(); 
		    reader.readAsDataURL(file); 
		    var delsrc='/img/close_icon.png';
		    reader.onload = function(e){
			    $(_self).parent().html('<img class="img_val img-width" src="'+this.result+'"/><img src="'+delsrc+'" class="del" title="\u5220\u9664"/>').css('border','none');
			    $(".uploadImg .del").unbind( "click" );
			    $(".img_val").click(function(){
			    	var url=$(this).prop("src");
					$(".imgload").show().addClass('imglager').html('<img src="'+url+'"/>');
				    $('#imgfade').show(); 
			    });
			    $(".uploadImg .del").click(function(){
					$(this).parent().remove();
					uploadImgMinNum--;
					var img = $(".uploadImg input[type='file']");
					if(img.length == 0){
						$(".uploadImg").append("<label class='result'><input type='file'>+</label>");
						document.querySelector(".uploadImg input[type='file']").addEventListener('change',readFile,false); 
						uploadImgMinNum++;
					}
			    });
				if(uploadImgMinNum < uploadImgMaxNum){
				    $(".uploadImg").append("<label class='result'><input type='file'>+</label>");
					document.querySelector(".uploadImg input[type='file']").addEventListener('change',readFile,false); 
					uploadImgMinNum++;
				}
			}
		//}
	}
};
$(document).ready(function(){
	$(".sort-input:not(.noclick)>div").click(function(){
    	$(this).toggleClass('sort-click')
	});
	$('#fontbianji,#imgbianji,.my_video_1').hover(function(){
	    $(this).siblings('div').removeClass('disn');
	}, function(){
		$(this).siblings('div').addClass('disn');
	});
});

//发布默认添加按钮关闭
function closeAdd(){
	$(".addtype").toggleClass('disn');
	$('.addicon').toggleClass('disn');
}
function addImg(){
	var getImg = document.querySelector(".uploadImg input[capture='camera']");
	if(typeof FileReader==='undefined'){
	    showImg.innerHTML = "抱歉，你的浏览器不支持 FileReader";
	    getImg.setAttribute('disabled','disabled');
	}else{
	    getImg.addEventListener('change',readFile,false);
	}
	function readFile(){
		//发布添加图片

		var file = this.files[0];
	    var reader = new FileReader();
	    reader.readAsDataURL(file);
	    reader.onload = function(e){
		    $('<div class="posre"><img class="img-width" src="'+this.result+'"/></div>').appendTo($(".content"));
		    $(".uploadImg .del").unbind( "click" );
		    $(".img_val").click(function(){
		    	var url=$(this).prop("src");
				$(".imgload").show().addClass('imglager').html('<img src="'+url+'"/>');
			    $('#imgfade').show(); 
		    });
		    $(".uploadImg .del").click(function(){
				$(this).parent().remove();
				uploadImgMinNum--;
				var img = $(".uploadImg input[type='file']");
				if(img.length == 0){
					$(".uploadImg").append("<label class='result'><input type='file'>+</label>");
					document.querySelector(".uploadImg input[type='file']").addEventListener('change',readFile,false); 
					uploadImgMinNum++;
				}
		    });
		}
	}
}
//发布添加视频
function addVideo(){
	var getImg = document.querySelector(".uploadImg input[capture='camcorder']"); 
	if(typeof FileReader==='undefined'){ 
	    showImg.innerHTML = "抱歉，你的浏览器不支持 FileReader"; 
	    getImg.setAttribute('disabled','disabled'); 
	}else{ 
	    getImg.addEventListener('change',readFile,false);  
	} 
	function readFile(){ 
	    var file = this.files[0];
	    var reader = new FileReader(); 
	    reader.readAsDataURL(file); 
	    reader.onload = function(e){
		    $('<div class="posre img-width"><img src="/img/playicon.png" class="playicon"/><video class="img-width my_video_1 pause" preload="auto" data-setup="{}" loop="loop"><source src="'+this.result+'" type="audio/mp4"></video></div>').appendTo($(".content"));
			$('video').click(function() {
				if ($(this).hasClass('pause')) {
					$("video").trigger("play");
					$(this).removeClass('pause');
					$(this).addClass('play');
					$(this).siblings('img').addClass('disn');
				} else {
					$("video").trigger("pause");
					$(this).removeClass('play');
					$(this).addClass('pause');
					$(this).siblings('img').removeClass('disn'); 
				}
			})
	    }
	}
}
//发布添加音频
function addAudeo(){
	var getImg = document.querySelector(".uploadImg input[capture='microphone']"); 
	if(typeof FileReader==='undefined'){ 
	    showImg.innerHTML = "抱歉，你的浏览器不支持 FileReader"; 
	    getImg.setAttribute('disabled','disabled'); 
	}else{ 
	    getImg.addEventListener('change',readFile,false);  
	} 
	function readFile(){ 
	    var file = this.files[0];
	    var reader = new FileReader(); 
	    reader.readAsDataURL(file); 
	    reader.onload = function(e){
		    $('<audio controls="controls" class="img-width"><source src="'+this.result+'" type="audio/mpeg"></audio>').appendTo($(".content"));
	    }
	}
}
$(function() {
	//position遇软键盘
	var positon=document.body.clientHeight;
	$('.dibu-fixed').css('top',positon-41);
	$('.bottomBar').css('top',positon-55);
    /*$('.login-bottom').css('top',positon-75);*/
    /*$('.addtype').css('top',positon-138);*/
    $('.login-bg').css('height',positon);
    $('.content').css('min-height',positon-55);
});

$(document).ready(function(){
	//买家订单订单状态选择
	$(".sort-input:not(.noclick)>div").click(function(){
    	$(this).toggleClass('sort-click')
	});
});
//买家订单筛选切换
function checkToptab(item,_this){
    var types = $(_this).text();
    $(".four").addClass('Cgray');
    $("#guige,#fade").show();
    $('body,.layout_content').css({"overflow":"hidden"});
    $('.layout_content').css({"height":"100%"});
    $(".four1,.four2").find('img').attr('src','/img/order_down.png');
    $('#payserch,#typeserch,#timeserch,#paystatus').addClass('disn');
    switch (item){
        case 'time':
            $(".four1").removeClass('Cgray');
            $(".four1").find('img').attr('src','/img/order_up.png');
            $('#timeserch').removeClass('disn');
            break;
        case 'type':
            $(".four2").removeClass('Cgray');
            $(".four2").find('img').attr('src','/img/order_up.png');
            $('#typeserch').removeClass('disn');
            break;
    }
}
//买家订单确定后关闭样式重置
function reset(){
	$(".sort-input>div").removeClass('sort-click');
}
function showFont(){
	$(".add-invoice").removeClass('disn');
}
function Closesearch(){
	reset();
    $("#guige,#fade").fadeOut();
    $(".four1,.four2").find('img').attr('src','/img/order_down.png');
    $(".four").addClass('Cgray');
    $('body,.layout_content').css({"overflow":""});
    $('.layout_content').css({"height":"auto"});
};
//立即支付预约时间显示
function timeShow(){
	ShowDiv();
	var date = new Date(); // new 一个Date对象
	var year = date.getFullYear(); // 年份
	var month = date.getMonth() + 1; // 月份（从0开始，所以应+1）
	var day=date.getDate();
	var days = new Date(year,month,0);
	var lastdate =days.getDate();
	var timeclass='time';
	var mine=' 14:16:00';
	var labelName='radio';
	var labelClass='disn';
	var labelType="radio";
	var flt='pay-select';
	var clear='clear_both';
	var id='se';
	var border='border1'
	for(var i = day+1;i <day +12&&i<=lastdate; i++) {
		if(month.toString().length==1){
			month='0'+month;
			//alert(month);
		}
		if(i.toString().length==1){
			i='0'+i;
			//alert(i);
		}
		$("<div class="+border+"><div class="+timeclass+" value="+ year + "-" + month + "-"+ i + mine+">" + year + "-" + month + "-"+ i+ mine+"</div><div class="+flt+" id="+id+"><input type="+labelType+" name="+labelName+" class="+labelClass+"/><label></label></div><div class="+clear+"></div></div>").appendTo($("#sese"));  // 依次添加下拉框选项，value自定义，右边的appendTo参数为目标选择框
	    $('#sese').children('.pay-select').eq(0).children('label').addClass('pay-check');
	    radioFunction();
	}
	if(i>lastdate){
		var month = date.getMonth() + 2;
		if(month>12){
			month=1;
		    year+=1
		}
		for(var i = 1;i <12-(lastdate-day); i++) {
			if(month.toString().length==1){
				month='0'+month;
			}
			if(i.toString().length==1){
				i='0'+i;
			}
			$("<div class="+timeclass+" value="+ year + "-" + month + "-"+ i + mine+">" + year + "-" + month + "-"+ i+ mine+"</div><div class="+flt+" id="+id+"><input type="+labelType+" name="+labelName+" class="+labelClass+"/><label></label></div><div class="+clear+"></div>").appendTo($("#sese"));
		    radioFunction();
		}
		//console.log(14-(lastdate-day));
	}
}
//时间显示按钮选择
function radioFunction(){
	$('.pay-select label').click(function(){
	    $(this).addClass('pay-check').parent().siblings().children('label').removeClass('pay-check');
	});
}
//浮层内容展示
function ShowDiv() {
	//console.log(1111);
    $("#fade").fadeIn("slow");
    $("#guige").slideDown();
    $('body,.layout_content').css("overflow","hidden");
    return false;
};
//浮层内容隐藏
function CloseDiv() {
    $("#guige").slideUp();
    $("#fade").fadeOut("slow");
    $('body,.layout_content').css("overflow","");
};
function ShowAccount(order_id) {
	$('.order_id').val(order_id);
    $("#fadeAccount,#account").fadeIn();
    $('body,.layout_content').css("overflow","hidden");
};
function CloseAccount(){
    $("#account,#fadeAccount").fadeOut();
    $('body,.layout_content').css("overflow","");
};
//商品数量减
function minus(el){
	var inputVal = $(el).next().find('input').val();
	var productId =$(el).attr('pid');
	if(inputVal<=0){
		return false;
	}
	var newVal = parseInt(inputVal)-1;
	$(el).next().find('input').val(newVal);
	//prouduct
	var productId =$(el).attr('pid');
	// 当数量为0 删除购物车产品
	if(newVal==0){

	}
}

//商品数量增加
function addCart(el){
	var inputVal = $(el).prev().find('input').val();
	var newVal = parseInt(inputVal)+1;
	$(el).prev().find('input').val(newVal);
}